#include "threadstudialog.h"
#include "ui_threadstudialog.h"
#include "../11-util/02-log_manager/logmanager.h"
#include <QString>

ThreadStuDialog::ThreadStuDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::ThreadStuDialog)
{
    ui->setupUi(this);
    loopThread = new LoopThread();
    noLoopThread = new NoLoopThread();
    connect(loopThread,&LoopThread::greet,this,&ThreadStuDialog::onGreet);
    connect(noLoopThread,&NoLoopThread::greet,this,&ThreadStuDialog::onGreet);
    connect(noLoopThread,&NoLoopThread::greet2,[=](){
        QString info = "slot lamda function threadid is %1";
        LogManager::debug("ThreadStuDialog","onGreet",info.arg(QString::number((long long)QThread::currentThreadId())));
    });

    connect(this,&ThreadStuDialog::hello,loopThread,&LoopThread::onHello);
}

void ThreadStuDialog::onGreet() {
    QString info = "slot function threadid is %1";
    QString info2 = info.arg(QString::number((long long)QThread::currentThreadId()));
    LogManager::debug("ThreadStuDialog","onGreet",info2);
}

ThreadStuDialog::~ThreadStuDialog()
{
    delete ui;
}

void ThreadStuDialog::on_btn_noLoop_clicked()
{
    QString info = "main thread id is %1";
    LogManager::debug("ThreadStuDialog","onNoLoopBtn","",info.arg(QString::number((long long)QThread::currentThreadId())));
    noLoopThread->start();
}


void ThreadStuDialog::on_btn_loop_clicked()
{
    QString info = "main threadid is %1";
    LogManager::debug("ThreadStuDialog","onLoopBtn",info.arg(QString::number((long long)QThread::currentThreadId())));
    loopThread->start();
    emit hello();
}

